package sr;

import java.util.*;

import SymbolTable.STPortEntry;

//////////////////////////////////////////////////////////////////////////
//// OutputPortDependency
/**

@author Ivan Jeukens
@version v 0.1 07/07/2003
*/
public class OutputPortDependency  {

    public OutputPortDependency(STPortEntry port) {
        _port = port;
        _depends = new HashMap();
        _dependsAll = false;
    }

    ///////////////////////////////////////////////////////////////////
    ////                        public methods                     ////

    public String getName() {
        return _port.getName();
    }
    
    public void setTotalInputs(int value) {
        _totalinputs = value;
    }
    
    public void addDependency(String inputport, LinkedList depVarList) {
        if(!_depends.containsKey(inputport)) {
            _depends.put(inputport, depVarList.clone());
        }
    }

    public Iterator dependencyIterator() {
        return _depends.keySet().iterator();
    }
    
    public boolean depends(String inputport) {
        return _depends.containsKey(inputport);
    }

    public int dependencySize() {
        return _depends.size();
    }

    public boolean dependsAll() {
        return ((_depends.size() == _totalinputs) || _dependsAll);
    }

    public void setDependsAll() {
        _dependsAll = true;
    }

    public String toString() {
        StringBuffer ret = new StringBuffer();
        ret.append("Output " + _port.getName() + " depends:\n");
        Iterator ite = _depends.keySet().iterator();
        while(ite.hasNext()) {
            String in = (String) ite.next();
            ret.append("\t Input Port: " + in + ". DeducedFrom: ");
            
            LinkedList ll = (LinkedList) _depends.get(in);
            for(int i = 0;i < ll.size() - 1;i++) {
            	ret.append(ll.get(i) + " -> ");
            }
            ret.append(ll.get(ll.size() - 1) + "\n");
        }
        return ret.toString();
    }
    
    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    ////

    ///////////////////////////////////////////////////////////////////
    ////                        private variables                  ////

    private STPortEntry _port;
    private HashMap _depends;
    private int _totalinputs;
    private boolean _dependsAll;
}
